var path = require("path");
// const webpack = require('webpack');
var { VueLoaderPlugin } = require("vue-loader");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const NODE_ENV = process.env.NODE_ENV;
console.log("NODE_ENV：", NODE_ENV);
const isPro = NODE_ENV === "production";
const isDev = NODE_ENV === "development";
const isDoc = NODE_ENV === "doc";

const options_devServer = {
  compress: true,
  port: 9000,
};
if (isDev) {
  options_devServer.static = {
    directory: path.join(__dirname),
  };
}
module.exports = {
  mode: NODE_ENV,
  entry: isDev ? "./src/main.js" : "./index.js",
  output: {
    path: path.resolve(__dirname, "./dist"),
    publicPath: isDev ? "/src/" : "",
    filename: isDev ? "main.js" : "peng-cascader.js",
    library: "peng-cascader",
    libraryTarget: "umd",
    umdNamedDefine: true,
  },
  devServer: options_devServer,
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: "vue-loader",
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, "css-loader"],
      },
      {
        test: /\.less$/,
        use: [
          {
            loader: "less-loader",
            options: {
              lessOptions: {
                javascriptEnabled: true,
              },
            },
          },
        ],
      },
    ],
  },
  resolve: {
    // 配置 省略文件后缀名
    extensions: [".js", ".css", ".vue"],
    alias: {
      vue: "vue/dist/vue.js",
    },
  },
  devtool: isDev ? "eval-source-map" : false,
  plugins: [
    new VueLoaderPlugin(),
    new MiniCssExtractPlugin({
      filename: "peng-cascader.css",
    }),
  ],
};
